<!-- 下拉滑动效果 -->
<script lang="ts" setup>
import { webImgs } from "@/hooks/images";
</script>

<template>
  <div class="slither">
    <div class="box"></div>
    <div class="cards">
      <template v-for="(card, inx) in webImgs" :key="inx">
        <div class="card">CARD1</div>
        <div class="card">CARD2</div>
        <div class="card">CARD3</div>
        <div class="card">CARD4</div>
        <div class="card"><el-image :src="card"></el-image></div>
      </template>
    </div>
    <div class="box"></div>
  </div>
</template>

<style lang="scss" scoped>
.slither {
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: auto;
  background: linear-gradient(
    to bottom right,
    #91defe,
    #99c0f9,
    #bdb6ec,
    #d7b3e3,
    #efb3d5,
    #f9bccc
  );
  .cards {
    display: grid;
    gap: 2em;
    // 控制自动放置的项目如何插入网格中  dense 放置项目以填充网格中的任何孔。
    grid-auto-flow: dense;
    // 定义网格的列数和列宽
    grid-template-columns: repeat(4, 40ch);
    margin: 100px auto;
    .card {
      display: flex;
      align-items: center;
      justify-content: center;
      width: 100%;
      height: 100%;
      color: #efefef;
      font-size: 32px;
      font-weight: 600;
      line-height: 6;
      letter-spacing: 4px; // 字间距
      border-radius: 8px;
      box-shadow: 0 0 20px rgba(0, 0, 0, 0.1);
      background: linear-gradient(
        to top left,
        #91defe,
        #99c0f9,
        #bdb6ec,
        #d7b3e3,
        #efb3d5,
        #f9bccc
      );
      overflow: hidden;
      animation: slide-fade-in both;
      // 动画时间线     跟随视口变化而变化
      animation-timeline: view();
      // 动画在 timeline 上的开始和结束位置
      animation-range: contain 0 contain 50%;

      &:nth-of-type(4n) {
        grid-column: span 2;
      }

      &:nth-of-type(5n) {
        grid-column: span 2;
      }

      &:nth-of-type(7n) {
        grid-row: span 2;
      }
    }
  }
  .box {
    height: 400px;
    background-color: pink;
  }
}

@keyframes slide-fade-in {
  from {
    opacity: 0;
    box-shadow: none;
    transform: scale(0.8) translate(-10px);
  }
}
</style>
